
package com.tools.cleanmaster.model.cloud;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * 客户端未知路径上传到服务端，服务端下发垃圾路径，这些垃圾路径需要定期去查询服务端针对这个路径是否有修改 该类用于管理，这些需要去服务端检查更新的路径
 */
public class TrashCloudPathData {
    private static TrashCloudPathData mInstance = null;
    private int mBunchNum = 20;
    private LinkedList<TrashFromCloud> mNeedUpdataList = new LinkedList<TrashFromCloud>();

    private TrashCloudPathData() {
    }

    public static TrashCloudPathData getInstance() {
        if (mInstance == null) {
            synchronized (TrashCloudPathData.class) {
                if (mInstance == null) {
                    mInstance = new TrashCloudPathData();
                }
            }
        }
        return mInstance;
    }

    public class TrashFromCloud {
        public long mPathIdString;
        public long mUpdateTime;
    }

    public void addTrashFromCloudItem(long pathId, long updateTime) {
        TrashFromCloud item = new TrashFromCloud();
        item.mPathIdString = pathId;
        item.mUpdateTime = updateTime;
        mNeedUpdataList.add(item);
    }

    public List<TrashFromCloud> getTrashFromCloudByBunch() {
        List<TrashFromCloud> needReturn = new ArrayList<TrashFromCloud>();
        if (mNeedUpdataList.size() > mBunchNum) {
            for (int i = 0; i < mBunchNum; i++) {
                needReturn.add(mNeedUpdataList.remove());
            }
        } else {
            needReturn = new ArrayList<TrashFromCloud>(mNeedUpdataList);
            mNeedUpdataList.clear();
        }
        return needReturn;
    }
}
